package com.hundsun.fcp.webplugin;

import java.util.EnumMap;

import android.os.Bundle;

import com.hundsun.fcp.webplugin.bean.TradeParamBase;

public class FundTradingHelper {
	public static final String FundTradingFunctionTag = "Fcp.FundTrading.Function";
	public static final String FundTradingParamTag = "Fcp.FundTrading.Param";

	public static FundTradingFunction getTradingFunction(Bundle pBundle) {
		if (pBundle.containsKey(FundTradingFunctionTag)) {
			return (FundTradingFunction) pBundle.get(FundTradingFunctionTag);
		}
		return null;
	}
	
	public static TradeParamBase getTradingParam(Bundle pBundle){
		if (pBundle.containsKey(FundTradingParamTag)) {
			return (TradeParamBase) pBundle.get(FundTradingParamTag);
		}
		return null;
	}

	public static <T extends TradeParamBase> Bundle getFundTradingArguments(
			FundTradingFunction pFunction, T paramT) {
		Bundle _Bundle = new Bundle();
		_Bundle.putSerializable(FundTradingFunctionTag, pFunction);
		if (paramT != null) {
			_Bundle.putSerializable(FundTradingParamTag, paramT);
		}
		return _Bundle;
	}

	/**
	 * 返回运行页面
	 * 
	 * @param pFundTradingFunction
	 * @return
	 */
	public static String getTradingPageFileName(
			FundTradingFunction pFundTradingFunction) {
		EnumMap _EnumMap = FundTradingFunctionConfig.getInstance()
				.getConfigItemMap();
		if (_EnumMap.containsKey(pFundTradingFunction)) {
			return ((FundTradingFunctionConfig.ConfigItem) _EnumMap
					.get(pFundTradingFunction)).pageFileName;
		}
		return null;
	}

	
	public static <T extends TradeParamBase> void setupTradingBundle(
			Bundle pBundle, FundTradingFunction pFunction, T pT)
			throws Exception {
		pBundle.putAll(getFundTradingArguments(pFunction, pT));
	}

}
